home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Online / hsc / source / hscprj / project.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-02  |  6.0 KB  |  275 lines

  1. /*
  2.  * This source code is part of hsc, a html-preprocessor,
  3.  * Copyright (C) 1995-1997  Thomas Aglassinger
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  */
  20. /*
  21.  * hscprj/project.c
  22.  *
  23.  * project managment routines for hsc
  24.  *
  25.  * updated: 12-Jan-1997
  26.  * created: 13-Apr-1996
  27.  */
  28.  
  29. #include <stdio.h>
  30. #include <stdarg.h>
  31. #include <string.h>
  32. #include <errno.h>
  33. #include <time.h>
  34.  
  35. #include "hsclib/ldebug.h"
  36. #include "hscprj/pdebug.h"
  37.  
  38. #include "ugly/utypes.h"
  39. #include "ugly/dllist.h"
  40. #include "ugly/expstr.h"
  41. #include "ugly/umemory.h"
  42. #include "ugly/infile.h"
  43. #include "ugly/ustring.h"
  44.  
  45. #include "hscprj/document.h"
  46. #include "hscprj/project.h"
  47.  
  48. /*
  49.  * new_project
  50.  */
  51. HSCPRJ *new_project(VOID)
  52. {
  53.     HSCPRJ *hp = (HSCPRJ *) umalloc(sizeof(HSCPRJ));
  54.  
  55.     if (hp)
  56.     {
  57.         memset(hp, 0, sizeof(HSCPRJ));
  58.         hp->documents = init_dllist(del_document);
  59.     }
  60.  
  61.     return (hp);
  62. }
  63.  
  64.  
  65. /*
  66.  * del_project
  67.  */
  68. VOID del_project(HSCPRJ * hp)
  69. {
  70.     if (hp)
  71.     {
  72.         del_dllist(hp->documents);
  73.         del_document(hp->document);
  74.         ufree(hp);
  75.     }
  76. }
  77.  
  78.  
  79. /*
  80.  * check_document_id
  81.  *
  82.  * append id to id_ref-list so it as checked when
  83.  * check_all_local_id_ref() is called
  84.  */
  85. int check_document_id(HSCPRJ * hp, STRPTR docname, STRPTR id)
  86. {
  87.     int err = ERR_CDI_OK;
  88.     HSCDOC *document = find_document(hp->documents, docname);
  89.  
  90.     DP(fprintf(stderr, DHP "  check id: `%s#%s'\n", docname, id));
  91.  
  92.     if (document)
  93.     {
  94.         HSCIDD *iddef = NULL;
  95.  
  96.         iddef = find_iddef(document, id);
  97.         if (!iddef)
  98.         {
  99.             DP(fprintf(stderr, DHP "    id unknown\n"));
  100.             err = ERR_CDI_NoID;
  101.         }
  102.         else
  103.         {
  104.             DP(fprintf(stderr, DHP "    id ok\n"));
  105.             err = ERR_CDI_OK;
  106.         }
  107.     }
  108.     else
  109.     {
  110.         DP(fprintf(stderr, DHP "    no file-entry in project\n"));
  111.         err = ERR_CDI_NoDocumentEntry;
  112.     }
  113.  
  114.     return (err);
  115. }
  116.  
  117. /*
  118.  * hsc_project_set_filename
  119.  *
  120.  * set project-filename (used by hsc_project_write_file())
  121.  */
  122. BOOL hsc_project_set_filename(HSCPRJ * hp, STRPTR new_prjname)
  123. {
  124.     BOOL ok = TRUE;
  125.     DP(fprintf(stderr, DHP "set project `%s'\n", new_prjname));
  126.  
  127.     if (hp->document->sourcename)
  128.     {
  129.         panic("project-name already set");
  130.     }
  131.  
  132.     hp->document->sourcename = strclone(new_prjname);
  133.  
  134.     return (ok);
  135. }
  136.  
  137. /*
  138.  * hsc_project_add_document
  139.  *
  140.  * add current document to project
  141.  */
  142. BOOL hsc_project_add_document(HSCPRJ * hp)
  143. {
  144.     BOOL ok = TRUE;
  145.  
  146.     if (hp->document)
  147.     {
  148.         if (hp->document->docname)
  149.         {
  150.             DP(fprintf(stderr, DHP "  add document `%s'\n",
  151.                        hp->document->docname));
  152.             app_dlnode(hp->documents, hp->document);
  153.         }
  154.         else
  155.         {
  156.             DP(fprintf(stderr, DHP "  add document <stdout>: skipped\n"));
  157.             del_document(hp->document);
  158.         }
  159.  
  160.         hp->document = NULL;
  161.     }
  162.     else
  163.     {
  164.         panic("no document to replace");
  165.     }
  166.  
  167.     return (ok);
  168. }
  169.  
  170. /*
  171.  * hsc_project_del_document
  172.  *
  173.  * remove document from project
  174.  */
  175. BOOL hsc_project_del_document(HSCPRJ * hp, STRPTR docname)
  176. {
  177.     BOOL deleted = FALSE;
  178.     DLNODE *docnd = find_document_node(hp->documents, docname);
  179.  
  180.     if (docnd)
  181.     {
  182.         DP(fprintf(stderr, DHP "  remove document `%s'\n", docname));
  183.         del_dlnode(hp->documents, docnd);
  184.         deleted = TRUE;
  185.     }
  186.     else
  187.     {
  188.         DP(fprintf(stderr, DHP "  remove document `%s': FAILED\n", docname));
  189.     }
  190.  
  191.     return (deleted);
  192. }
  193.  
  194. /*
  195.  * hsc_project_set_document
  196.  *
  197.  * Remove document from project's document list and
  198.  * create a new empty document with this name and
  199.  * make it the current document of the project.
  200.  * The new document is added to the project when the
  201.  * project-file is updated.
  202.  */
  203. BOOL hsc_project_set_document(HSCPRJ * hp, STRPTR new_docname)
  204. {
  205.     BOOL ok = TRUE;
  206.     DLNODE *nd = NULL;
  207.     if (new_docname)
  208.     {
  209.         DP(fprintf(stderr, DHP "set document `%s'\n", new_docname));
  210.  
  211.         /* dettach document from project */
  212.         nd = find_document_node(hp->documents, new_docname);
  213.         if (nd)
  214.         {
  215.             DP(fprintf(stderr, DHP "  remove old document `%s'\n",
  216.                        ((HSCDOC *) dln_data(nd))->docname));
  217.             del_dlnode(hp->documents, nd);
  218.         }
  219.         else
  220.         {
  221.             DP(fprintf(stderr, DHP "  new document `%s'\n", new_docname));
  222.         }
  223.     }
  224.     else
  225.     {
  226.         DP(fprintf(stderr, DHP "set document <stdout>\n"));
  227.     }
  228.  
  229.     /* remove current document */
  230.     if (hp->document)
  231.     {
  232.         DP(fprintf(stderr, DHP "  remove current document `%s'\n",
  233.                    hp->document->docname));
  234.         del_document(hp->document);
  235.     }
  236.  
  237.     hp->document = new_document(new_docname);
  238.  
  239.     return (ok);
  240. }
  241.  
  242. /*
  243.  * hsc_project_set_source
  244.  *
  245.  * set main source for project's current document
  246.  */
  247. BOOL hsc_project_set_source(HSCPRJ * hp, STRPTR new_sourcename)
  248. {
  249.     BOOL ok = TRUE;
  250.     DP(fprintf(stderr, DHP "set source `%s'\n", new_sourcename));
  251.  
  252.     if (!hp->document->sourcename)
  253.         hp->document->sourcename = strclone(new_sourcename);
  254.     else
  255.     {
  256.         panic("sourcename already set");
  257.         ok = FALSE;
  258.     }
  259.  
  260.     return (ok);
  261. }
  262.  
  263. /*
  264.  * hsc_project_add_include
  265.  *
  266.  * add include-file to project's current document
  267.  */
  268. BOOL hsc_project_add_include(HSCPRJ * hp, STRPTR new_includename)
  269. {
  270.     BOOL ok = TRUE;
  271.     DP(fprintf(stderr, DHP "add include `%s'\n", new_includename));
  272.     app_include(hp->document, new_includename);
  273.     return (ok);
  274. }
  275.